import java.util.ArrayList;
import java.util.LinkedList;
import java.util.List;
import java.util.ListIterator;

public class Test {
    public static void main(String[] args) {
        List<Integer> list = new LinkedList<>();
        List<Integer> list1 = new ArrayList<>();

        list1.add(1);
        list1.add(2);
        //默认尾插法
        list.add(1);
        list.add(2);
        list.add(3);
        list.add(4);
        List<Integer> list2 = list.subList(0, 2);
        list2.set(0, 99);
        System.out.println(list);
        list.add(2, 4);
        list.set(2, 3);
        list1.addAll(list);
        System.out.println(list1);
        // foreach遍历
        for (int e : list) {
            System.out.print(e + " ");
        }
        System.out.println();
// 使用迭代器遍历---正向遍历
        ListIterator<Integer> it = list.listIterator();
        while (it.hasNext()) {
            System.out.print(it.next() + " ");
        }
        System.out.println();
// 使用反向迭代器---反向遍历
        ListIterator<Integer> rit = list.listIterator(list.size());
        while (rit.hasPrevious()) {
            System.out.print(rit.previous() + " ");
        }
        System.out.println();
    }

    public static void main1(String[] args) {
        MyLinkedlist myLinkedlist = new MyLinkedlist();
        myLinkedlist.addLast(1);
        myLinkedlist.addLast(2);
        myLinkedlist.addLast(3);
        myLinkedlist.addLast(4);
        myLinkedlist.addIndex(2,10);
        myLinkedlist.addFirst(10);
        myLinkedlist.addLast(10);
        System.out.println(myLinkedlist.size());
        System.out.println(myLinkedlist.contains(10));
        myLinkedlist.display();
        myLinkedlist.remove(10);
        myLinkedlist.display();
        myLinkedlist.removeAllKey(10);
        myLinkedlist.display();
    }
}
